package cn.zswltech.gruul.biz.service.impl;

import cn.zswltech.gruul.biz.service.GroupOaService;
import cn.zswltech.gruul.web.api.util.CookieUtils;
import cn.zswltech.gruul.common.util.ShaUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName GroupOaServiceImpl
 * @Description TODO
 * @Author jackerhe
 * @Date 2022/9/5 10:44 上午
 * @Version 1.0
 **/
@Service
public class GroupOaServiceImpl implements GroupOaService {

    @Value("${trade.notice.privateKey}")
    private String privateKey;

    @Override
    public Boolean checkTocken(HttpServletRequest request) {
        String random = CookieUtils.getCookieValByName(request, CookieUtils.OA_RANDOM);
        String secret = CookieUtils.getCookieValByName(request, CookieUtils.OA_SECRET);
        String timestamp = CookieUtils.getCookieValByName(request, CookieUtils.OA_TIMESTAMP);
        if (ObjectUtils.isEmpty(random) || ObjectUtils.isEmpty(secret) || ObjectUtils.isEmpty(timestamp)) {
            return Boolean.FALSE;
        }
        return secret.equals(ShaUtil.shaEncode(privateKey.concat(timestamp).concat(random)));
    }
}
